package org.cadet.client.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.cadet.client.bean.BeanUser;
import org.cadet.client.model.UserManagement;

/**
 * @author Nagmani
 * 
 */

public class Profile extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Profile() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out = response.getWriter();
		try {
			HttpSession session = request.getSession();
			BeanUser user = new BeanUser();
			UserManagement objUserManagement = new UserManagement();
			int currentUserId = objUserManagement.getUserIdByName((String)session.getAttribute("user"));
			String status = "";
			try{
				user = objUserManagement.viewUserByUserId(currentUserId);
				status = "success";
			}
			catch(Exception e){
				status = "fail";
			}
			request.setAttribute("status", status);
			request.setAttribute("user", user);
			RequestDispatcher rd = request.getRequestDispatcher("changepassword.jsp");
			rd.forward(request, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			out.close();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
